package com.cmbchina.entity;

import java.math.BigDecimal;
import java.util.Objects;

public class SohuExchangeRate {
    private BigDecimal rate;
    private Currency fromCurrency;
    private Currency toCurrency;

    public SohuExchangeRate(BigDecimal rate, Currency fromCurrency, Currency toCurrency) {
        setRate(rate);
        setFromCurrency(fromCurrency);
        setToCurrency(toCurrency);
    }

    public BigDecimal getRate() {
        return rate;
    }

    public void setRate(BigDecimal rate) {
        //对服务返回汇率进行校验
        if(Objects.isNull(rate) || rate.compareTo(BigDecimal.ZERO) <= 0){
            throw new IllegalArgumentException("rate is invalid");
        }

        this.rate = rate;
    }

    public void setFromCurrency(Currency fromCurrency) {
        this.fromCurrency = fromCurrency;
    }

    public void setToCurrency(Currency toCurrency) {
        this.toCurrency = toCurrency;
    }

    public Currency getFromCurrency() {
        return fromCurrency;
    }

    public Currency getToCurrency() {
        return toCurrency;
    }

}
